Skip to content

[APPS][Connections Part 6] Build backend module graph during backend builds#353

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
sdkennedy2/reachable-module-graph-call-sites
May 13, 2026
Merged

[APPS][Connections Part 6] Build backend module graph during backend builds#353
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
sdkennedy2/reachable-module-graph-call-sites

Conversation

@sdkennedy2
Copy link
Copy Markdown
Collaborator

@sdkennedy2 sdkennedy2 commented May 10, 2026

Motivation

Prepare backend connection ID analysis to use the same module graph that backend bundling already sees, without moving connection ID extraction into this PR.

Changes

This PR adds module graph collection to the backend build path used by both production builds and the dev server. During each backend build, the Vite collector observes Rollup moduleParsed events and records app-local, parseable source modules with their transformed ASTs, canonical module IDs, static dependency IDs, and unsupported local dependency facts.

For example, this backend module:

// /app/src/backend/actions.backend.ts
import { getMessage } from "./helpers";

export async function run() {
    return getMessage();
}

Produces a collected module record shaped like this:

{
    id: "/app/src/backend/actions.backend.ts",
    ast: Program,
    staticDependencies: ["/app/src/backend/helpers.ts"],
    unsupportedDependencies: [],
}

The Vite-specific adapter owns Rollup module ID normalization and virtual module filtering, while the backend AST module graph code works with canonical app-local module IDs. That keeps bundler details out of the reusable graph record layer.

This PR intentionally stops at building the graph. Traversing the graph to collect connection IDs from reachable modules is handled in the next PR in the stack. Existing same-file backend connection ID behavior remains unchanged.

QA Instructions

Updated the focused unit coverage for backend module graph record creation and Vite collector behavior. Also ran the apps plugin typecheck and lint coverage for the changed module graph and backend build integration paths.

Validated the change against a local test app to confirm backend functions still build and upload while existing same-file allowedConnectionIds behavior remains unchanged.

Blast Radius

This affects the apps plugin backend build path by collecting module graph metadata during backend builds. The collected graph is not used to change emitted allowedConnectionIds behavior in this PR, so runtime behavior should remain unchanged.

Documentation

@sdkennedy2 sdkennedy2 changed the title Discover action calls in reachable modules [APPS][WIP] Discover action calls in reachable modules May 10, 2026
@sdkennedy2
Copy link
Copy Markdown
Collaborator Author

@codex review
@cursor review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e118c97bcd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/plugins/apps/src/backend/ast-parsing/module-graph-connection-ids.ts Outdated
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch 2 times, most recently from 89e014a to 6e7a15a Compare May 10, 2026 23:06
@sdkennedy2 sdkennedy2 changed the base branch from sdkennedy2/same-module-connection-id-values to graphite-base/353 May 11, 2026 13:11
@sdkennedy2 sdkennedy2 force-pushed the graphite-base/353 branch from 908d3d4 to d7a3e8c Compare May 11, 2026 15:52
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch from 6e7a15a to 93ee73a Compare May 11, 2026 15:52
@sdkennedy2 sdkennedy2 changed the base branch from graphite-base/353 to sdkennedy2/get-vite-plugin-refactor May 11, 2026 15:52
@sdkennedy2 sdkennedy2 changed the title [APPS][WIP] Discover action calls in reachable modules [APPS][Connections Part 6] Discover action calls in reachable modules May 11, 2026
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/get-vite-plugin-refactor branch from d7a3e8c to cb0c1ca Compare May 11, 2026 16:54
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch 2 times, most recently from 1b1f8fa to 5e9d380 Compare May 11, 2026 17:50
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/get-vite-plugin-refactor branch 2 times, most recently from 5ce434d to 67e2595 Compare May 11, 2026 18:58
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch from 5e9d380 to fc121d3 Compare May 11, 2026 18:58
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/get-vite-plugin-refactor branch from 67e2595 to ad770f4 Compare May 11, 2026 19:04
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch 3 times, most recently from 4297d54 to c0eab57 Compare May 11, 2026 22:22
@sdkennedy2 sdkennedy2 changed the title [APPS][Connections Part 6] Discover action calls in reachable modules [APPS][Connections Part 6] Collect backend action calls during backend builds May 12, 2026
Base automatically changed from sdkennedy2/get-vite-plugin-refactor to master May 12, 2026 18:21
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch from 0e3d954 to b941937 Compare May 12, 2026 18:42
@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented May 12, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 31f9122 | Docs | Datadog PR Page | Give us feedback!

@sdkennedy2 sdkennedy2 changed the title [APPS][Connections Part 6] Collect backend action calls during backend builds [APPS][Connections Part 6] Build backend module graph during backend builds May 13, 2026
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch 4 times, most recently from c3f66bf to a00cd6b Compare May 13, 2026 16:41
Copy link
Copy Markdown
Collaborator Author

AI reviewer note:

I moved the Vite/Rollup-specific module ID handling out of packages/plugins/apps/src/backend/ast-parsing/module-graph.ts and into packages/plugins/apps/src/vite/backend-module-graph-collector.ts.

The core module graph code now assumes canonical app-local source module IDs. The Vite collector is responsible for adapting Rollup ModuleInfo into that shape by stripping query suffixes and skipping \0... / virtual:... module IDs. This keeps bundler-specific virtual module details out of the backend AST/module graph layer.

Comment thread packages/plugins/apps/src/vite/index.ts Outdated
Comment thread packages/plugins/apps/src/vite/dev-server.ts Outdated
Comment thread packages/plugins/apps/src/vite/build-backend-functions.ts Outdated
Comment thread CLAUDE.md Outdated
Comment thread packages/plugins/apps/src/backend/ast-parsing/module-graph.test.ts Outdated
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch from a00cd6b to ce6fdd3 Compare May 13, 2026 17:00

export type StringLiteral = SimpleLiteral & { value: string };

type TypeOnlyAwareNode = BaseNode & { importKind?: string; exportKind?: string };
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

importKind and exportKind are not part of the base estree they are part of the typescript AST fyi.

@sdkennedy2 sdkennedy2 marked this pull request as ready for review May 13, 2026 17:10
@sdkennedy2 sdkennedy2 requested review from a team and yoannmoinet as code owners May 13, 2026 17:10
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/reachable-module-graph-call-sites branch from ce6fdd3 to 4780d00 Compare May 13, 2026 17:26

type ImportCallExpression = SimpleCallExpression & { callee: { type: 'Import' } };

const DISALLOWED_GRAPH_DIRS = new Set(['node_modules', 'dist', 'build', '.vite']);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build seems potentially something a user could name a folder. We have that folder name inside one of our repos for example.

Also should we include .yarn? Any other folders that we might want? Should this be configurable?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are good questions. A given module would need to be referenced via an import. This DISALLOWED_GRAPH_DIRS is checked against each module path. Perhaps we should remove dist, build, .vite since they are unlikely to be referenced in an import statement and make sure we also cover yarn's package location as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, in that case, we may only need node_modules as any .yarn imports necessarily also includes node_modules inside the import path (after the .zip)

Comment thread packages/plugins/apps/src/backend/ast-parsing/module-graph.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants